<?php

	/**
	 * c_user controller
	 *
	 * @package application
	 * @subpackage controller
	 * @author con100 <con100@playplus.net>
	 * @since 18/04/2013
	 * @copyright Copyright (c) 2013, PlayPlus
	 **/

	class C_user extends CI_Controller
	{
		// post method value
		var $param = null;

		/**
		 * constructor
		 **/
		public function __construct()
		{
			parent::__construct();
			$this->load->model('c_user');
		}

		public function index()
		{
			$this->param = $this->input->post();
			
			if (method_exists($this, $this->param['mode'])) {
				$this->{$this->param['mode']}();
			} 
			else {
				show_error('protocol error!');
			}
		}

		/**
		 * @brief get_user_data protocol
		 *
		 * @param post uid User Id
		 * @return 
		 * @author con100 <con100@playplus.net>
		 * @since 09/04/2013
		 * @copyright Copyright (c) 2013, PlayPlus
		 **/

		private function get_user_data()
		{
			if (empty($this->param['uid'])) $this->param['uid'] = null;

			$result = $this->m_user->get_user_data($this->param['uid']);
			$this->load->view('result_json', $result);

		}

		/**
		 * @brief recovery_hp protocol
		 *
		 * @param post uid User ID
		 * @return 
		 * @author con100 <con100@playplus.net>
		 * @since 05/04/2013
		 * @copyright Copyright (c) 2013, PlayPlus
		 **/

		private function recovery_hp()
		{
			if (empty($this->param['uid'])) $this->param['uid'] = null;

			$result = $this->m_user->get_user_data($this->param['uid']);
			$this->load->view('result_json', $result);
		}

		/**
		 * @brief change_max_hp protocol
		 *
		 * @param post uid User ID
		 * @return 
		 * @author con100 <con100@playplus.net>
		 * @since 05/04/2013
		 * @copyright Copyright (c) 2013, PlayPlus
		 **/

		private function change_max_hp()
		{
			if (empty($this->param['uid'])) $this->param['uid'] = null;

			$result = $this->m_user->get_user_data($this->param['uid']);
			$this->load->view('result_json', $result);
		}

		/**
		 * @brief change_stat protocol
		 *
		 * @param post uid User ID
		 * @param post stat_a User Atk_Stat
		 * @param post stat_b User Hit_Stat
		 * @param post stat_c User Def_Stat
		 * @param post stat_d User Spd_Stat
		 * @return 
		 * @author con100 <con100@playplus.net>
		 * @since 11/04/2013
		 * @copyright Copyright (c) 2013, PlayPlus
		 **/

		private function change_stat()
		{
			if (empty($this->param['uid'])) $this->param['uid'] = null;
			if (empty($this->param['stat_a'])) $this->param['stat_a'] = null;
			if (empty($this->param['stat_b'])) $this->param['stat_b'] = null;
			if (empty($this->param['stat_c'])) $this->param['stat_c'] = null;
			if (empty($this->param['stat_d'])) $this->param['stat_d'] = null;

			$result = $this->m_user->get_user_data($this->param['uid'],$this->param['stat_a'],$this->param['stat_b'],$this->param['stat_c'],$this->param['stat_d']);
			$this->load->view('result_json', $result);
		}

		/**
		 * @brief change_comment protocol
		 *
		 * @param post uid User ID
		 * @param post comment User Comment
		 * @return 
		 * @author con100 <con100@playplus.net>
		 * @since 05/04/2013
		 * @copyright Copyright (c) 2013, PlayPlus
		 **/
		private function change_comment()
		{
			if (empty($this->param['uid'])) $this->param['uid'] = null;
			if (empty($this->param['comment'])) $this->param['comment'] = null;

			$result = $this->m_user->get_user_data($this->param['uid'],$this->param['comment']);
			$this->load->view('result_json', $result);
		}
	}